package micro86.engine;

/**
 * Created with IntelliJ IDEA.
 * User: alar
 * Date: 12.03.13
 * Time: 15:03
 * To change this template use File | Settings | File Templates.
 */
public class Memory {
    private final int memoryLength = 64;
    private byte[] memoryArray = new byte[memoryLength];

    public int gelValue(int cellNum) throws  MemoryException{
        if (cellNum > (memoryLength - 4) || cellNum < 0){
            new MemoryException("No access to specified cell.");
        }
        int n = cellNum;
        return memoryArray[n]<<24 + memoryArray[n+1]<<16 + memoryArray[n+2]<<8 + memoryArray[n+3];
    }

    public void setValue(int cellNum, int value) throws MemoryException{
        if (cellNum > (memoryLength - 4) || cellNum < 0){
            new MemoryException("No access to specified cell.");
        }
        int n = cellNum;
        memoryArray[n] = (byte)(value >>> 24);
        memoryArray[n+1] = (byte)(value >>> 16);
        memoryArray[n+2] = (byte)(value >>> 8);
        memoryArray[n+3] = (byte)(value);
    }
}
